package com.jeesite.modules.information.service;

import cn.hutool.core.util.IdUtil;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.common.service.ServiceException;
import com.jeesite.common.utils.excel.ExcelImport;
import com.jeesite.common.validator.ValidatorUtils;
import com.jeesite.modules.information.dao.CereShopOrderDao;
import com.jeesite.modules.information.entity.CereShopOrder;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.List;

/**
 * 日常体征Service
 *
 * @author laz
 * @version 2024-05-09
 */
@Service
public class CereShopOrderService extends CrudService<CereShopOrderDao, CereShopOrder> {

    @Autowired
    private CereShopOrderDao cereShopOrderDAO;

    /**
     * 获取单条数据
     *
     * @param cereShopOrder
     * @return
     */
    @Override
    public CereShopOrder get(CereShopOrder cereShopOrder) {
        return super.get(cereShopOrder);
    }

    /**
     * 查询分页数据
     *
     * @param cereShopOrder 查询条件
     * @param cereShopOrder page 分页对象
     * @return
     */
    @Override
    public Page findPage(CereShopOrder cereShopOrder) {
        // Long total = cereShopOrderDAO.getAll_COUNT(cereShopOrder);
        // System.out.println("phone:" + cereShopOrder.getPhone());
        // System.out.println("phone:" + cereShopOrder.getBeginCreateTime());
        // System.out.println("phone:" + cereShopOrder.getEndCreateTime());
		Long total = cereShopOrderDAO.getAll_COUNT1(cereShopOrder.getPhone(), cereShopOrder.getBeginCreateTime()
				, cereShopOrder.getEndCreateTime(), cereShopOrder.getShopNameLike(), cereShopOrder.getProductNameLike());
        // System.out.println("total:" + total);
        // if (total == null || total <= 0) {
        //     return new Page();
        // }
        Integer pageNo = cereShopOrder.getPage().getPageNo();
        Integer pageSize = cereShopOrder.getPage().getPageSize();
        PageHelper.startPage(pageNo, pageSize);
        List<CereShopOrder> list = cereShopOrderDAO.getAll(cereShopOrder);
        PageInfo<CereShopOrder> pageInfo = new PageInfo<>(list);

        cereShopOrder.getPage().setList(pageInfo.getList());
        cereShopOrder.getPage().setCount(total);
        // cereShopOrder.getPage().setCount(pageInfo.getTotal());

        cereShopOrder.getPage().initialize();
        return cereShopOrder.getPage();
        // return super.findPage(cereShopOrder);
    }


    /**
     * 保存数据（插入或更新）
     *
     * @param cereShopOrder
     */
    @Override
    @Transactional
    public void save(CereShopOrder cereShopOrder) {
        User user = UserUtils.getUser();
        // cereShopOrder.setUserCode(user.getUserCode());
        // super.save(cereShopOrder);
    }

}